package com.dao.imp;

import java.util.List;

import org.hibernate.Query;

import com.dao.RoominfoDao;
import com.dao.core.DaoBaseImp;
import com.pojo.Roominfo;

public class RoominfoDaoImp extends DaoBaseImp<Roominfo> implements RoominfoDao{

	@Override
	public Roominfo getRoominfo(Integer id) {
		
		return (Roominfo)getSession().get(Roominfo.class, id);
	}

	@Override
	public List<Roominfo> getAvaliableRoominfoDao(Roominfo roominfo) {
		
		return null;
	}

	@Override
	public Roominfo getRoominfoByAddr(String buildingNum, String floor,
			String roomNum) {
		String hql = " from Roominfo as ri where ri.buildingNum=:buildingNum and ri.floor =:floor and ri.roomNum=:roomNum";
		Query query = getSession().createQuery(hql);
		query.setString("buildingNum", buildingNum);
		query.setString("floor", floor);
		query.setString("roomNum",roomNum);
		return (Roominfo)query.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<String> getfloorByBuildingNum(String buildingNum) {
		String hql="select ri.floor from Roominfo as ri where ri.buildingNum =:buildingNum";
		Query query = getSession().createQuery(hql);
		query.setString("buildingNum", buildingNum);
		return (List<String>)query.list();
		
	}

	@Override
	public List<String> getroomNumByBuildingNumAndFloor(String buildingNum,
			String floor) {
		String hql="select ri.roomNum from Roominfo as ri where ri.buildingNum =:buildingNum and ri.floor=:floor";
		Query query = getSession().createQuery(hql);
		query.setString("buildingNum", buildingNum);
		query.setString("floor", floor);
		return (List<String>)query.list();
	}

	@Override
	public List<Roominfo> getroomNumByBuildingNum(String buildingNum) {
		String hql="from Roominfo as ri where ri.buildingNum =:buildingNum";
		Query query = getSession().createQuery(hql);
		query.setString("buildingNum", buildingNum);
		return query.list();
	}
}
